package k8s

import (
	"fmt"

	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type K8sConfitMap struct {
	Name string						`json:"name"`
	Labels map[string]string		`json:"labels"`
	CreateDate string				`json:"createdate"`

	Namespace string				`json:"namespace"`
	Data map[string]string			`json:"data"`

}

func GetConfigmapDetail(ns string,name string)(configmap K8sConfitMap,err error) {
	configMap, _ := clientset.CoreV1().ConfigMaps(ns).Get(name,metav1.GetOptions{})

	configmap = K8sConfitMap{
		Name: configMap.Name,
		Namespace: configMap.Namespace,
		Labels: configMap.Labels,
		CreateDate: configMap.CreationTimestamp.Format("2006-01-02"),

		Data: configMap.Data,

	}
	return
}


func getConfigmapList(ns string)(configmaps []K8sConfitMap,err error) {
	configMaps, _ := clientset.CoreV1().ConfigMaps(ns).List(metav1.ListOptions{})
	fmt.Println(len(configMaps.Items))
	for _,item := range configMaps.Items {
		fmt.Printf("%+v\n",item)
		configmaps = append(configmaps,K8sConfitMap{
			Name: item.Name,
			Labels: item.Labels,
			CreateDate: item.CreationTimestamp.Format("2006-01-02"),
		})
	}
	return
}